package com.szr.cloud.springboot_hello.reactor;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.szr.cloud.springboot_hello.model.User;
import com.szr.cloud.springboot_hello.service.UserServiceI;

import reactor.core.Reactor;
import reactor.event.Event;
import reactor.spring.annotation.Selector;

@Component
public class UserHandler {

	@Autowired
	private UserServiceI userService;
	
	@Autowired
	@Qualifier("rootReactor")
	private Reactor r;
	
	@Selector(value="saveUser",reactor="@rootReactor")
	public void saveUser(Event<Map<String,Object>> evt){
		Map<String, Object> map = evt.getData();
		User user = (User)map.get("user");
		userService.saveUser(user);
	}
}
